<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>分店采购订单表</title>
<link rel="stylesheet" href="../../res/mln/layui.css" media="all">
</head>
<body>
	<div class="demoTable">
		搜索关键字：
		<div class="layui-inline" >
			<input class="layui-input" name="id" id="demoReload"
				autocomplete="off">
		</div>
		
		时间：
		<div class="layui-input-inline">
      	  	<input name="dateOne" id="dateOne" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
      	——<div class="layui-input-inline">
      	  	<input name="dateTwo" id="dateTwo" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
		<button class="layui-btn" data-type="reload">搜索</button>
		
		
		<table class="layui-hide" id="fdPurchase" lay-filter="demo"></table>
	</div>

<script type="text/html" id="barDemo">

  <a class="layui-btn layui-btn-xs" lay-event="detail" >查看详情</a>
   {{# if(d.fdPoState=="审核失败"){ }}
    <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="xgsh">修改</a>
   <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
   {{# } else if(d.fdPoState=="总店总经理审核成功"){}}
   		 {{# if(d.tuihuo=="0"){ }}
           <a class="layui-btn layui-btn-disabled  layui-btn-xs" lay-event="salesReturn">退货</a>
        {{# } else if(d.tuihuo==1){}}
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="salesReturn">退货</a>
		{{# } }}


   {{# }else if(d.fdPoState=="mmm"){}}
   {{# } }}
</script>



<script src="../../res/js/jquery-1.10.2.js"></script>
<script src="../../res/js/layui-xtree.js"></script>
<script src="../../layui/layui.js"></script>
<script src="../../res/js/base.js"></script>



<script>
                                                                                                                                                                                                                                                                                    
layui.use(['form','laydate', 'laypage', 'layer', 'table', 'upload', 'element','tree'], function(){
  var form = layui.form
  ,laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格
  ,upload = layui.upload //上传
  ,element = layui.element; //元素操作
  var path=getRootPath();
  
  
  var endDate= laydate.render({
      elem: '#dateTwo',//选择器结束时间
      //type: 'datetime',
      min:"2001-12-31",//设置min默认最小值  0表示今天 -1表示昨天  1表示明天
      max:"2099-12-31",
      done: function(value,date){
          startDate.config.max={
              year:date.year,
              month:date.month-1,//关键
              date: date.date
             
          }
      }
  });
  //日期范围
  var startDate=laydate.render({
      elem: '#dateOne',
    //  type: 'datetime',
      min:"2001-12-31",
      max:"2099-12-31",//设置一个默认最大值
      done: function(value, date){
          endDate.config.min ={
              year:date.year,
              month:date.month-1, //关键
              date: date.date
             
          };
      }
  });
  
  //日期
  laydate.render({
	    elem: '#dateOne'
  });
  laydate.render({
	    elem: '#dateTwo'
  });

  
  //上传文件
  var uploadInst = upload.render({
      elem: '#upload1' //绑定元素
      ,url: path+'member/uploadFile.action' //上传接口
      ,before: function(obj){
          //预读本地文件示例，不支持ie8
          obj.preview(function(index, file, result){
        	  
              $('#demoOne').attr('src', result); //图片链接（base64）
          });
      }
      ,done: function(res){
          //如果上传失败
          if(res.code > 0){
              return layer.msg('上传失败');
          }
          //上传成功
          document.getElementById("img_url").value = res.url;

      }
      ,error: function(){
          //演示失败状态，并实现重传
          var demoText = $('#demoText');
          demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
          demoText.find('.demo-reload').on('click', function(){
              uploadInst.upload();
          });
      }
  });
  //上传文件
  var uploadInsts = upload.render({
      elem: '#uploadTwo' //绑定元素
      ,url: path+'member/uploadFile.action' //上传接口
      ,before: function(obj){
          //预读本地文件示例，不支持ie8
          obj.preview(function(index, file, result){
        	  
              $('#demoTow').attr('src', result); //图片链接（base64）
          });
      }
      ,done: function(res){
          //如果上传失败
          if(res.code > 0){
              return layer.msg('上传失败');
          }
          //上传成功
          document.getElementById("img_urlTwo").value = res.url;

      }
      ,error: function(){
          //演示失败状态，并实现重传
          var demoText = $('#demoTextTwo');
          demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
          demoText.find('.demo-reload').on('click', function(){
        	  uploadInsts.upload();
          });
      }
  });
  
  //监听Tab切换
  element.on('tab(demo)', function(data){
    layer.msg('切换了：'+ this.innerHTML);
    console.log(data);
  });
  
  //执行一个 table 实例
  table.render({
     elem: '#fdPurchase'
    ,async: false
    ,height: 474
    ,url: path+'FdPurchase/findAlls.action' //数据接口
    ,page: true //开启分页
    ,method:'post'
    ,cols: [[ //表头
       {field: 'fdPoId', title: '采购订单ID', width:80 }
      ,{field: 'manId', title: '用户ID', width:80}
      ,{field: 'tuihuo', title: '已退货', width:80}
      ,{field: 'fdPoPerson', title: '采购人员', width:120}
      ,{field: 'fdSunnum', title: '采购总数量', width:120}
      ,{field: 'fdSumprice', title: '采购总价格', width:120}
      ,{field: 'fdPoTimess', title: '采购时间', width:120}
      ,{field: 'fdPoState', title: '采购状态', width:120}
      ,{field: 'fdPoRemark', title: '采购备注', width:120}
      ,{field: 'fdNumber', title: '批次号', width:120}
      
      ,{fixed: 'right',title: '操作', width: 245, align:'center', toolbar: '#barDemo'}
    ]]
  	,id: 'testReload'
  });
  
  //监听工具条
  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
    
    var fdPoId = data.fdPoId;
    if(layEvent === 'del'){
      var reId=data.reId;
      layer.confirm('确认删除？', function(index){
        obj.del(); //删除对应行（tr）的DOM结构
        layer.close(index);
        //使用jquery的ajax方式向后台提交数据
		var url = path+"salesReturn/deleteReId.action";
		var data={reId:reId};
			$.post(url,data,function(data){
				
				if(data=="ok"){
					layer.msg('删除成功', {
						  icon: 1,
						  time: 1000 //1秒关闭（如果不配置，默认是3秒）
						}, function(){
						  
					});
				}
			});
      	});
    } else if(layEvent === 'edit'){
	      
	      $("#memberName").val(data.memberName);
	      
	      $("#memberNumber").val(data.memberNumber);
	      $("#menmberPwd").val(data.menmberPwd);
	      $("#img_urlTwo").val(data.memberImage);
	      $("#demoTow").attr("src",path+data.memberImage); 
	      $("#memberId").val(data.memberId);
	      
	      var m=$("#isva").children().next();
	      var n=$("#isva").children();
	      
	      if(m.val()==data.memberSort){      
	         m.attr("selected",true);
	      }else{
	    	 n.attr("selected",true);
	      }
	      form.render("select");
	      $('#updateReload').css('display','block');
	      
	}else if(layEvent === 'detail'){
    	layer.open({
			title:'采购订单详情'
			,type:2
			,area:['75%' , '70%']
			,content:[path+'pages/mln/fdPurchaseList.html?fdPoId='+fdPoId,'yes']
		});
    }else if(layEvent === 'salesReturn'){
    	var tuihuo = data.tuihuo;
    	//判断退货与 已退货状态
    	if(tuihuo==0){
    		 layer.msg('订单已退货，无法操作', {
				  icon: 1,
				  time: 3000 //1秒关闭（如果不配置，默认是3秒）
				}, function(){
					// location.reload(); // 页面刷新
			});
    	}
    	
    	if(tuihuo==1){
    		var fdPoId = data.fdPoId;
    	
    		layer.open({
    			title:'采购详情'
    			,type:2
    			,area:['85%','80%']
    			//设置滚蛋条 yes为开启  no为关闭
    			,content:[path+'pages/mln/fdPoBreakdown.html?fdPoId='+fdPoId,'yes']
    		});
   		}
    	
    
		
		
    }else if(layEvent === 'xgsh'){
    	layer.open({
			  type: 2,
			  area : ['75%' , '80%'],//弹出框大小
			  shift:1,//弹出框动画效果
			  content: [path+'pages/mln/fdPurchaseUpdate.html?fdPoId='+fdPoId,'on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		 	 
		});
    }
    
   
    });

		//条件查询
		var $ = layui.$;

		$('.demoTable .layui-btn').on('click', function() {
			var demoReload = $('#demoReload');
			//执行重载
			table.reload('testReload', {
				page : {
					curr : 1
				//重新从第 1页开始
				},
				where : {
					fdPoPerson : demoReload.val(),
					dateOne: $("#dateOne").val(),
					dateTwo: $("#dateTwo").val(),
				}
			});
		});
		$('#closeAdd').on('click', function() {
			$('#addReload').css('display', 'none');
		});
		$('#closeUpdate').on('click', function() {
			
			$('#updateReload').css('display', 'none');
		});
		
		$('#memberAdd').on('click', function() {
			$('#addReload').css('display', 'block');
			
		});
	});
</script>
<script>

</script>
</body>
</html>